package com.redis.controller;

import com.redis.entity.User;
import com.redis.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@EnableAutoConfiguration
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ResponseBody
    @RequestMapping(value = "/add", produces = {"application/json;charset=UTF-8"})
    public int addUser(User user) {
        return userService.addUser(user);
    }

    @ResponseBody
    @RequestMapping(value = "/all/{pageNum}/{pageSize}", produces = {"application/json;charset=UTF-8"})
    public Object findAllUser(@PathVariable("pageNum") int pageNum, @PathVariable("pageSize") int pageSize) {
        return userService.findAll(pageNum, pageSize);
    }

    @ResponseBody
    @RequestMapping(value = "/findById", method = RequestMethod.POST)
    public Object findDevice(@RequestBody Map<String, Object> params) {
        String deviceId = params.get("deviceId").toString();
        return userService.findDevice(deviceId);
    }

    @ResponseBody
    @RequestMapping(value = "/find")
    public Object findUser() {
        return userService.selectByPrimaryKey("2");
    }

    @ResponseBody
    @RequestMapping(value = "/findCity1")
    public Object findCity() {
        return userService.findAll();
    }

    @ResponseBody
    @RequestMapping(value = "/findDevice")
    public Object findDevice() {
        return userService.findAllDevice();
    }


    @ResponseBody
    @RequestMapping(value = "/findCityByPopulation/{population}")
    public Object findCityByPopulation(@PathVariable("population") int population) {
        return userService.findCityByPopulation(population);
    }

}
